package com.chen.script.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.chen.script.annotation.Job;
import com.chen.script.feign.RemoteSystemService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author ChenJinLong
 */
@Data
@Slf4j
@Component
@ConfigurationProperties(prefix = "win-server")
@ConditionalOnProperty(value = "win-server.enable", havingValue = "true")
public class UpdateServerDateTimeJob {

    @Resource
    private RemoteSystemService remoteSystemService;

    public UpdateServerDateTimeJob(){
        log.info("初始化 更新Windows服务器系统时间 JOB");
    }

    @Job(value = "win-server")
    public void run() {
        DateTime dateTime = DateUtil.date(System.currentTimeMillis());
        String date = DateUtil.format(dateTime, "yyyy/MM/dd");
        String time = DateUtil.format(dateTime, "HH:mm:ss");
        log.info("更新Windows服务器系统时间: {} {}", date, time);

        remoteSystemService.updateSystemDateTime(date, time);
    }

}
